package com.comtime.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.comtime.smartkilimanjaro.R;

public class MyDialog extends Dialog {

	View view;
	Context context;
	TextView tv_title, tv_content;
	Button btn_left, btn_right;
	RelativeLayout relative_area;
	View line_vertical;

	float k;

	public MyDialog(Context context) {
		super(context, R.style.MyDialog);
		this.context = context;
		view = LayoutInflater.from(context).inflate(R.layout.dialog_my, null);
		relative_area = (RelativeLayout) view.findViewById(R.id.relative_area);
		tv_title = (TextView) view.findViewById(R.id.text_title);
		tv_content = (TextView) view.findViewById(R.id.text_content);
		btn_left = (Button) view.findViewById(R.id.btn_mydialog_left);
		btn_right = (Button) view.findViewById(R.id.btn_mydialog_right);
		line_vertical = view.findViewById(R.id.line_vertical);
		k=context.getResources().getDisplayMetrics().density;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setCanceledOnTouchOutside(false);
		if (btn_right.getText() == null || btn_right.getText().equals("")) {
			btn_right.setVisibility(View.GONE);
			line_vertical.setVisibility(View.GONE);
		}
		int n = 20;
		if (context.getResources().getConfiguration().locale.getCountry()
				.equals("CN")) {
			n = 25;
		} else {
			n = 36;
		}
		int m = tv_title.getText().toString().length() / (n-5)
				+ tv_content.getText().toString().length() / n;// ����20��Ӣ��40
		int mmmmm = (int) ((130 + m * 30) * k);
		if("service@smartwallit.com".equals(tv_content.getText().toString())){
			tv_content.getPaint().setFakeBoldText(true);
			tv_content.setTextSize(18);
			mmmmm=(int) (mmmmm-15*k);
		}
		if(	tv_content.getText().toString().equals("www.smartwallit.com")){
			tv_content.getPaint().setFakeBoldText(true);
			tv_content.setTextSize(18);
			mmmmm=(int) (mmmmm-15*k);
		}
		RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
				(int) (250 * k), mmmmm);
		relative_area.setLayoutParams(param);
		
		
		tv_title.getPaint().setFakeBoldText(true);
		if(tv_title.getText().toString()==null ||tv_title.getText().toString().equals("")){
			tv_title.setVisibility(View.GONE);
		}
		if(tv_content.getText().toString()==null ||tv_content.getText().toString().equals("")){
			tv_content.setVisibility(View.GONE);
		}else {
	
		}
		
		this.setContentView(view);
	}

	@Override
	public void setTitle(CharSequence title) {
		tv_title.setText(title);
	}

	/**
	 * setTitle
	 */
	@Override
	public void setTitle(int titleId) {
		tv_title.setText(titleId);

	}

	/**
	 * 
	 * @param content
	 *            dddd
	 */
	public void setContent(CharSequence content) {
		tv_content.setText(content);
	}

	/**
	 * 
	 * @param contentId
	 */
	public void setContent(int contentId) {
		tv_content.setText(contentId);
	}

	/**
	 * 
	 * @param text
	 */
	public void setLeftButtonText(CharSequence text) {
		btn_left.setText(text);
	}
	public void setLeftButtonText(int textid) {
		btn_left.setText(textid);
	}
	/**
	 * 
	 * @param text
	 */
	public void setRightButtonText(CharSequence text) {
		btn_right.setText(text);
	}
	public void setRightButtonText(int textid) {
		btn_right.setText(textid);
	}
	/**
	 * 
	 * @return
	 */
	public Button getLeftButton() {
		return btn_left;
	}

	/**
	 * 
	 * @return
	 */
	public Button getRighrButton() {
		return btn_right;
	}

}
